<template>
  <div>
    <el-form :inline="true" :model="headerForm" class="demo-form-inline" style="margin: 0px 15px;">
      <el-form-item label="一级分类">
        <el-select v-model="headerForm.categoryId1" placeholder="请选择一级分类" @change="getCategory2List"
                   :disabled="addOrUpdateTagShow">
          <el-option :label="c1.name" :value="c1.id" v-for="c1 in headerForm.categoryList1" :key="c1.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select v-model="headerForm.categoryId2" placeholder="请选择二级分类" @change="getCategory3List"
                   :disabled="addOrUpdateTagShow">
          <el-option :label="c2.name" :value="c2.id" v-for="c2 in headerForm.categoryList2" :key="c2.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select v-model="headerForm.categoryId3" placeholder="请选择三级分类" @change="getparam"
                   :disabled="addOrUpdateTagShow">
          <el-option :label="c3.name" :value="c3.id" v-for="c3 in headerForm.categoryList3" :key="c3.id"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {getCategory1List, getCategory2List, getCategory3List} from '@/api/swagger'

export default {
  name: "HeaderInput",
  data() {
    // 这里存放数据
    return {
      headerForm: {
        categoryId1: '',
        categoryList1: [],
        categoryId2: '',
        categoryList2: [],
        categoryId3: '',
        categoryList3: [],
      }
    }
  },
  // import 引入的组件需要注入到对象中才能使用
  components: {},
  props: ['getHeaderParam', 'addOrUpdateTagShow'],
  // 方法集合
  methods: {
    async getCategory1List() {
      await getCategory1List().then(res => {
        if (res.code == 200) {
          this.headerForm.categoryList1 = res.data
        }
      })
    },
    async getCategory2List(categoryId1) {
      this.headerForm.categoryId2 = '',
        this.headerForm.categoryList2 = [],
        this.headerForm.categoryId3 = '',
        this.headerForm.categoryList3 = [],
        this.getHeaderParam(this.headerForm)
      await getCategory2List(categoryId1).then(res => {
        if (res.code == 200) {
          this.headerForm.categoryList2 = res.data
        }
      })
    }, async getCategory3List(categoryId2) {
      this.headerForm.categoryId3 = '',
        this.headerForm.categoryList3 = [],
        this.getHeaderParam(this.headerForm)
      await getCategory3List(categoryId2).then(res => {
        if (res.code == 200) {
          this.headerForm.categoryList3 = res.data
        }
      })
    },
    getparam() {
      this.getHeaderParam(this.headerForm);
      this.$emit('queryAttrList');
    }
  },
  mounted() {
    this.getCategory1List();
  }
}
</script>

<style scoped>
</style>
